import javax.security.auth.login.CredentialNotFoundException;
import java.util.Comparator;
import java.util.Objects;
import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Solitudefire
 * Date: 2022-08-01
 * Time: 15:44
 */


//class RankCompartor implements Comparator<Card> {
//
//    @Override
//    public int compare(Card o1, Card o2) {
//        return o1.rank - o2.rank;
//    }
//}

//class Card implements Comparable<Card>{
//    public int rank;//数值
//    public String suit;//花色
//    public Card (int rank,String suit){
//        this.rank = rank;
//        this.suit = suit;
//    }
//
//    @Override
//    public int compareTo(Card o) {
//        return this.rank - o.rank;
//    }
//
//    @Override
//    public String toString() {
//        return "Card{" +
//                "rank=" + rank +
//                ", suit='" + suit + '\'' +
//                '}';
//    }
//}
class Card {

    public int rank;//数值
    public String suit;//花色

    public Card(int rank, String suit) {
        this.rank = rank;
        this.suit = suit;
    }

    @Override
    public String toString() {
        return "Card{" +
                "rank=" + rank +
                ", suit='" + suit + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        //getClass() != o.getClass()比较的是同一个类型
        if (o == null || getClass() != o.getClass()) return false;
        Card card = (Card) o;
        return rank == card.rank && Objects.equals(suit, card.suit);
    }

    @Override
    public int hashCode() {
        return Objects.hash(rank, suit);
    }
}

public class TestDemo {
    public static void main(String[] args) {
        Card card1 = new Card(1, "♥");
        Card card2 = new Card(1, "♥");
        System.out.println(card1.equals(card2));
    }


    public static void main4(String[] args) {
        //RankCompartor rankCompartor = new RankCompartor();
//        PriorityQueue<Card> priorityQueue = new PriorityQueue<>(new Comparator<Card>() {
//            @Override
//            public int compare(Card o1, Card o2) {
//                return o1.rank - o2.rank;
//            }
//        });
        PriorityQueue<Card> priorityQueue = new PriorityQueue<>((x, y) -> {
            return x.rank - y.rank;
        });
        Card card1 = new Card(1, "♥");
        Card card2 = new Card(2, "♥");
        priorityQueue.offer(card1);
        priorityQueue.offer(card2);
        System.out.println(priorityQueue);
    }

    public static void main3(String[] args) {
//        PriorityQueue<Card> priorityQueue = new PriorityQueue<>();
//        Card card1 = new Card(1, "♥");
//        Card card2 = new Card(2, "♥");
//        RankCompartor rankCompartor = new RankCompartor();
//        int ret = rankCompartor.compare(card1, card2);
//        System.out.println(ret);


//        priorityQueue.offer(new Card(2,"♥"));
//        priorityQueue.offer(new Card(1,"♥"));
//        System.out.println(priorityQueue);
    }

    public static void main2(String[] args) {
        //默认是一个小根堆
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        //每放一个元素 都得保证当前的堆 是一个大堆 或者小堆
        priorityQueue.offer(12);
        priorityQueue.offer(3);
        priorityQueue.offer(15);
        System.out.println(priorityQueue.poll());
        System.out.println(priorityQueue.poll());
    }

    public static void main1(String[] args) {
        int[] array = {27, 15, 19, 18, 28, 34, 65, 49, 25, 37};
        TestHeap testHeap = new TestHeap();
        testHeap.createBigHeap(array);
//        testHeap.offer(80);
        testHeap.heapSort();
        System.out.println("====================");
//        System.out.println(testHeap.poll());
//        System.out.println(testHeap.poll());
    }


}
